package io.xuan.modules.app.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;


@Slf4j
public class VideoWebSocketHandler extends TextWebSocketHandler {

    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        String payload = message.getPayload();
        log.info("Received message: " + payload);

        // 解析 currentTime
        double currentTime = Double.parseDouble(payload);

        // 根据 currentTime 处理数据，并生成响应
        String response = processDataBasedOnCurrentTime(currentTime);

        // 发送响应消息
        session.sendMessage(new TextMessage(response));
    }

    private String processDataBasedOnCurrentTime(double currentTime) {
        // 根据 currentTime 处理数据的逻辑
        // 例如：返回一些根据 currentTime 生成的数据
        return "Data for currentTime: " + currentTime;
    }
}
